package no.ntnu.fp.utils;

import java.awt.Color;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

import no.ntnu.fp.model.Employee;

public class ColorGenerator {
	private static Map<Employee, Color> colorMap = new HashMap<Employee, Color>();
	private static Stack<Color> buffer = new Stack<Color>();
	private static int r = 255, g = 20, b = 147;
	
	public static Color getColor(Employee employee){
		if(!colorMap.containsKey(employee)){
			generateColor(employee);
		}
		return colorMap.get(employee);
	}
	
	public static void removeEmployee(Employee employee){
		Color c = colorMap.get(employee);
		buffer.push(c);
		colorMap.remove(employee);
	}
	
	private static void generateColor(Employee employee){
		if(buffer.isEmpty()){
			Color c = new Color(r, g, b);
			if(r + 50 >= 255){
				if(g + 50 >= 255){
					if(b + 50 >= 255){
						r = 0;
					}else{
						b += 50;
					}
				}else{
					g += 50;
				}
			}else{
				r += 50;
			}
			colorMap.put(employee, c);
		}else{
			colorMap.put(employee, buffer.pop());
		}
	}
}
